<template>
	<view>
		<view class="blue-column-border-box">
			<view class="blue-border"></view>
			<view class="blue-text">预约信息确认</view>
		</view>
		<view class="gray-box">
			<view class="top-row-box">
				<text class="left left-text">就诊人</text>
				<text class="right right-text">{{user.id}}{{user.name}}</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">挂号费</text>
				<text class="right right-text"><text style="color: #FFD39B;">{{yuyueinfo.price}}</text>元</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">科室</text>
				<text class="right right-text">{{keshiName}}</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">医院</text>
				<text class="right right-text">中国医科大学附属医院</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">看诊医生</text>
				<text class="right right-text">{{doctorName}}</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">预约排号</text>
				<text class="right right-text">{{yuyueinfo.time}} {{yuyueinfo.number}}号</text>
			</view>
			<view class="top-row-box">
				<text class="left left-text">就诊时间</text>
				<text class="right right-text">{{yuyueinfo.date}}</text>
			</view>
		</view>
		<view class="blue-column-border-box">
			<view class="blue-border"></view>
			<view class="blue-text">症状描述</view>
		</view>
		<view class="gray-box">
			<textarea class="input-area" v-model="zhengzhuang"/>
		</view>
		<button class="button" @click="insureAppoint()">马上预约</button>
		</view>
	</view>
</template>

<script>
	import {
		getIsCardOverIimit,
		getUserCardInfo,
	} from '@/common/api/userInfo.js'
	import {
		error
	} from '@/common/js/errorTips.js'
	import {
		getKeshiName,
		findyishengByid,
		quguahao,
	} from '@/common/api/jh/doctor.js'
	export default {
		data() {
			return {
				showCardId: false,
				selectId: 0,
				isOverLimit: false,
				cardList: [],
				iconURL: '/static/center/card/',
				cardID: uni.getStorageSync('cardID') || '',
				cardName: '',
				selectName: '',
				selectId: uni.getStorageSync('cardID') || '',
				visitInfo: {}, // 就诊信息
				clinicName: '',
				hospital: '',
				yuyueinfo:{},
				user:{
					id:0,
					name:''
				},
				doctorName:'',
				keshiName:'',
				zhengzhuang: ''
			}
		},
		methods: {
			// 点击确定
			insureAppoint: function() {
				console.log(this.zhengzhuang+"this.zhengzhuang")
				if(this.zhengzhuang==''||this.zhengzhuang==undefined){
					error('请添加症状！')
				}else{
					let that = this;
					uni.showModal({
						title: '挂号',
						content: '确认支付'+this.yuyueinfo.price+'块挂号吗',
						success(res) {
							if(res.confirm) {
								uni.showLoading({
									title: '挂号中'
								})
								var datas = {
											yonghu: that.user.id,
											yisheng: that.yuyueinfo.yisheng,
											riqi: that.yuyueinfo.date,
											shijian: that.yuyueinfo.time,
											feiyongflag: Number(that.yuyueinfo.price),
											okflag: Number(that.yuyueinfo.number),
											zhengzhuang: that.zhengzhuang
											}
								quguahao(datas.yonghu, datas.yisheng, datas.riqi, datas.shijian, datas.feiyongflag, 
								datas.okflag, datas.zhengzhuang).then(res => {
									uni.hideLoading()
									if(res.data=='SUCCESS'){
										uni.showToast({
											title: '挂号成功',
											icon: 'success'
										})
										setTimeout(function(){
											uni.switchTab({
												url: '/pages/yuyue/application'
											})
										},2000)
									}else if(res.data=='CF'){
										error('您在此时段已挂过号啦，请勿重复挂号！')
									}else if(res.data=='YBY'){
										error('该医生在此时段已被预约，请选择其他时段进行预约！')
									}else{
										error('挂号出错，请稍后重试！')
									}
									console.log("结果"+res.data)
								}).catch(() => {
									error('网络故障')
								})
								console.log(JSON.stringify(datas))
							}
						}
					})
				}
				
			},
			getKeshiName(keshi){
				getKeshiName(keshi).then(res => {
					this.keshiName = res.data!=''?res.data:keshi
				}).catch(() => {
					error('网络故障')
				})
			},
			findyishengByid(yisheng){
				findyishengByid(yisheng).then(res => {
					this.doctorName = res.data.name!=''?res.data.name:yisheng
				}).catch(() => {
					error('网络故障!')
				})
			},
		},
		onLoad() {
			var info1 = JSON.parse(uni.getStorageSync("yuyue1"))
			var info2 = JSON.parse(uni.getStorageSync("yuyue2"))
			this.yuyueinfo.yisheng = info1.yisheng
			this.yuyueinfo.date = info1.date
			this.yuyueinfo.keshi = info1.keshi
			this.yuyueinfo.time = info2.time
			this.yuyueinfo.number = info2.number
			this.yuyueinfo.price = info2.price
			this.findyishengByid(this.yuyueinfo.yisheng)
			this.getKeshiName(this.yuyueinfo.keshi)
			console.log(JSON.stringify(this.yuyueinfo))
			var user = {
				id: uni.getStorageSync('userLoginInfo.id'),
				name:uni.getStorageSync('userLoginInfo.name')
			}
			this.user = user
			console.log(JSON.stringify(user))
		}
	}
</script>

<style lang="scss">
	@import '@/common/scss/common.scss';
	@import '@/common/scss/form.scss';
	page{
		@extend .page-backgroud;
	}
	.gray-box{
		@extend .gray-border-box;
		.top-row-box{
			@include width-margin(95%, 100rpx);
			@include row-left-right(35%, 65%);
			line-height: 100rpx;
			.left-text{
				@include font-style(16px, bold, #000000);
			}
			.right-text{
				@include font-style(16px, 500, $gray-color);
			}
		}
		.bottom-row-box{
			@include width-margin(95%, 100rpx);
			@include row-left-right(50%, 50%);
			line-height: 100rpx;
			.right-text{
				width: 60%;
				@include font-style(16px, 500, $gray-color);
			}
			.left-icon-text-box{
				// width: 40%;
				height: 100%;
				@include flex-direction(row);
				align-items: center;
				.icon{
					@include icon-size(50rpx,50rpx);
					margin-right: 20rpx;
				}
				.left-text{
					@include font-style(16px, bold, #000000);
				}
			}
		}
		.top-row-box:not(:last-child){
			border-bottom: 1px solid $border-color;
		}
		.bottom-row-box:not(:last-child){
			border-bottom: 1px solid $border-color;
		}
	}
	// 按钮的颜色
	.button{
		@extend .button-box;
		margin-top: 50rpx;
	}
	.input-area{
		height: 50px;
	}
</style>
